
import { createRouter, createWebHistory,RouteRecordRaw } from 'vue-router'
import {digElMessage} from "../common/Message.ts";
const routes: Array<RouteRecordRaw> = [

    {
       path:"/shareFile/:uuid",
        name:"shareFile",
        component:()=>import('../share/UserShare.vue')

    },

    {
        path:"/user_login",
        name:"user_login",

        component:()=> import('../page/UserLogin.vue'),
    },
    {
        path:"/index",
        name:"index",

        component:()=> import("../components/index.vue")
    },
    {
        path:"/user_register",
        name:"user_register",

        component:()=> import('../page/UserRegister.vue'),
    },



    {
        path:"/file",
        name:"file",
        meta:{name:"全部文件"},
        component:()=> import("../components/index.vue"),
        children:[
            {
                path:"/img_file",
                name:"imgFile",
                meta:{name:'图片',isShow:true},
                component:()=> import("../components/file/ImgFile.vue")},

            {
            path:"/audio",
            name:"audio",
            meta:{
              name:'音频',isShow:true
            },
            component:()=> import("../components/file/AudioFrequency.vue")},
            {
                path:"/vidio_file",
                name:"vidioFile",
                meta:{name:'视频',isShow:true},
                component:()=> import("../components/file/VidioFile.vue")},
            {
                path:"/document",
                name:"document",
                meta:{name:'文档',isShow:true},
             component:()=> import("../components/file/DocumentFile.vue")},
            // {
            //     path:"/seed",
            //     name:"seed",
            //     meta:{name:'种子',isShow:true},
            //     component:()=> import("../components/file/Seed.vue")},
            //
            // {
            { path:"/more_file",
                name:"moreFile",
                meta:{name:'更多',isShow:true},
                component:()=> import("../components/file/MoreFile.vue")},


        ]
    },
    {
        path:"/other",
        name:"other",
        meta:{name:'其他'},
        component:()=> import("../components/index.vue"),
        children:[
            {
                path:"/share",
                name:"share",
                meta:{name:'我的分享',isShow:true},
                component:()=> import("../components/other/MyShare.vue")},
            {
                path:"/recy",
                name:"recy",
                meta:{name:'回收站',isShow:true},
                component:()=> import("../components/other/Recyclebin.vue")},

            {
                path:"/downing",
                name:"downing",
                meta:{name:'正在下载',isShow:false},
                component:()=> import("../components/operation/AllDown.vue")},
            {
                path:"/uploading",
                name:"uploading",
                meta:{name:'正在上传',isShow:false},
                component:()=> import("../components/operation/AllUpload.vue")},
            {
                path:"/share_file",
                name:"share_file",
                meta:{name:'分享',isShow:false},
                component:()=> import("../components/operation/FileShare.vue")},
            {
                path:"/file_info",
                name:"file_info",
                meta:{name:'网盘',isShow:false},
                component:()=> import("../components/operation/AllFile.vue")},
        ]
    },

]
const router = createRouter({
    history: createWebHistory(),
    routes
})


// //前置路由守卫
//@ts-ignore
router.beforeEach((to, from, next) => {
    // 全局前置守卫逻辑
        if(to.path.startsWith("/shareFile")){
            next();
        }

    let atoken=localStorage.getItem("token");
  if(to.path=="/user_login"||to.path=="/user_register"){
     next();}


    else if(atoken==null){

        digElMessage("未登录请登录","warning",1000)
        next("/user_login")
    }


   else{
        next();
    }

});

export default router;